package com.eshin.autotest.service;

import com.eshin.autotest.bean.OrderBean;
import com.eshin.configuration.HelloConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;

import javax.annotation.PostConstruct;
import java.util.concurrent.Executor;

/**
 * @author Eshin
 * @title: HelloConfiguration
 * @projectName pay
 * @date 2019/5/2816:59
 */

@Configuration
@Import(HelloConfiguration.class)
@AutoConfigureBefore(HelloConfiguration.class)
public class HelloConfiguration2 {

    @PostConstruct
    public void init(){
        System.out.println("HelloConfiguration2 init...");
    }
    @Bean
    @ConditionalOnMissingBean(OrderBean.class)
    public OrderBean orderBean2(){
        System.out.println("create custom default orderbean in HelloConfiguration2");
        return new OrderBean();
    }

    @Configuration
    @Import(HelloService.class)
    class HelloConfigurationInner2{
        @PostConstruct
        public void init(){
            System.out.println("HelloConfigurationInner2 init...");
        }
        @Bean
//        @ConditionalOnMissingBean(name="getStr30")
        public String getStr2(){
            System.out.println("helloTest in HelloConfigurationInner2");
            return "helloTest";
        }
    }

    @Configuration
    static class HelloConfigurationInner20{
        @PostConstruct
        public void init(){
            System.out.println("HelloConfigurationInner20 init...");
        }
        @Bean
        public String getStr20(){
            System.out.println("helloTest in HelloConfigurationInner20 String");
            return "helloTest";
        }
        @Bean
        public Executor  getStr20(Executor executor){
            System.out.println("helloTest in HelloConfigurationInner20 executor");
            return executor;
        }


        /**
         * 没有@Bean注解不参与候选选举
         * @param hello
         * @return
         */
        public OrderBean  getStr20(OrderBean hello){
            System.out.println("helloTest in HelloConfigurationInner20 executor");
            return hello;
        }
//        两者参数个数一样多，无法判断哪个才是被选召的孩子
//        @Bean
//        public String getStr20(OrderBean hello){
//            System.out.println("helloTest in HelloConfigurationInner20");
//            return "helloTest"+hello;
//        }

        @Bean
        @Lazy
        public String getStr200(String str){
            System.out.println("helloTest in HelloConfigurationInner20 str"+str);
            return "helloTest"+str;
        }

        @Bean
        @Lazy
        public String getStr200(int num){
            System.out.println("helloTest in HelloConfigurationInner20 num"+num);
            return "helloTest"+num;
        }



    }
}
